package o;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.service.installdepend.bean.GetDetailByIdResBean;
import com.huawei.appmarket.service.installdepend.bean.GetDetailByIdResBean$DetailInfoBean;
import com.huawei.appmarket.service.thirdappdl.ThirdAppDownloadActivityProtocol;
import com.huawei.appmarket.service.thirdappdl.ThirdAppDownloadActivityProtocol.Request;
import java.util.List;
import o.dws.d;
import o.ewm.n;

public class dwu implements d {
    private static boolean ˊ = false;
    private int ʼ;
    private BaseCardBean ˋ;
    private String ˎ;
    private Context ˏ;
    private int ॱ;
    private String ᐝ;

    static class b implements IServerCallBack {
        private BaseCardBean ˊ;
        private String ˋ;
        private Context ˎ;
        private int ˏ;
        private int ॱ;

        b(Context context, BaseCardBean baseCardBean, String str, int i, int i2) {
            this.ˎ = context;
            this.ˊ = baseCardBean;
            this.ˋ = str;
            this.ॱ = i;
            this.ˏ = i2;
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            dwu.ˊ = false;
            GetDetailByIdResBean getDetailByIdResBean = (GetDetailByIdResBean) responseBean;
            if (getDetailByIdResBean.getResponseCode() == 3) {
                evk.ˏ(this.ˎ, n.ʳॱ);
            } else if (getDetailByIdResBean.getResponseCode() == 0) {
                List ˏ = getDetailByIdResBean.ˏ();
                if (!CollectCheck.isEmpty(ˏ)) {
                    GetDetailByIdResBean$DetailInfoBean getDetailByIdResBean$DetailInfoBean = (GetDetailByIdResBean$DetailInfoBean) ˏ.get(0);
                    if (getDetailByIdResBean$DetailInfoBean == null) {
                        return;
                    }
                    if (getDetailByIdResBean$DetailInfoBean.ᐝॱ() != 0) {
                        Logger.ˎ("DeepLinkWithVersionEventListener", "can not download, app nonAdaptType is " + getDetailByIdResBean$DetailInfoBean.ᐝॱ());
                        dwv.ॱ(this.ˎ, getDetailByIdResBean$DetailInfoBean.ʻ(), this.ˊ.ॱॱ(), this.ˊ.u_());
                        return;
                    }
                    String ˊॱ = getDetailByIdResBean$DetailInfoBean.ˊॱ();
                    if (!(this.ˎ instanceof Activity) || ((Activity) this.ˎ).isFinishing()) {
                        Logger.ˋ("DeepLinkWithVersionEventListener", "context is not instance of Activity or is finishing");
                        return;
                    }
                    cjo thirdAppDownloadActivityProtocol = new ThirdAppDownloadActivityProtocol();
                    Request request = new Request();
                    request.ˊ(this.ॱ);
                    request.ˋ(this.ˏ);
                    request.ˏ(this.ˋ);
                    request.ˊ(this.ˎ.getString(n.ՙˊ, new Object[]{ˊॱ}));
                    request.ॱ(getDetailByIdResBean$DetailInfoBean.ʻ());
                    request.ˋ(this.ˊ.ॱॱ());
                    thirdAppDownloadActivityProtocol.ˊ(request);
                    cjk.ˎ().ˋ(this.ˎ, new cjm("deeplink.download.activity", thirdAppDownloadActivityProtocol));
                }
            } else {
                evk.ˏ(this.ˎ, n.ᐝʼ);
            }
        }
    }

    public void ˋ(@NonNull Context context, String str, String str2, @NonNull BaseCardBean baseCardBean) {
        this.ˏ = context;
        this.ˋ = baseCardBean;
        this.ˎ = str;
        this.ᐝ = str2;
        this.ॱ = ॱ(str2);
        this.ʼ = erz.ˎ(context, str);
        if (this.ʼ < this.ॱ) {
            ˊ();
        } else if (dwv.ˊ(str)) {
            new dws(context, str, baseCardBean.ॱॱ(), this).ˏ(context);
        } else {
            ॱ(context, baseCardBean, str, str2);
        }
    }

    static boolean ˏ(String str) {
        return ॱ(str) >= 0;
    }

    private static int ॱ(String str) {
        if (!TextUtils.isEmpty(str)) {
            Uri parse = Uri.parse(str);
            Object ˏ = ceb.ˏ(parse, "V");
            if (TextUtils.isEmpty(ˏ)) {
                ˏ = ceb.ˏ(parse, "v");
            }
            if (!TextUtils.isEmpty(ˏ)) {
                try {
                    return Integer.parseInt(ˏ);
                } catch (NumberFormatException e) {
                    Logger.ˋ("DeepLinkWithVersionEventListener", "Format error! cannot parse versionCode to Integer");
                }
            }
        }
        return -1;
    }

    private void ˊ() {
        if (!ˊ) {
            ˊ = true;
            cfw.ˎ(new eaj(this.ˎ), new b(this.ˏ, this.ˋ, this.ᐝ, this.ʼ, this.ॱ));
        }
    }

    private void ॱ(Context context, BaseCardBean baseCardBean, String str, String str2) {
        int ˋ = dwv.ˋ(context, baseCardBean.ॱॱ(), str, str2);
        if (ˋ != -2) {
            if (ˋ == -1) {
                dwv.ॱ(context, str, baseCardBean.י(), baseCardBean.u_());
            }
            dwv.ˏ(context, baseCardBean.ॱॱ(), str, str2, ˋ);
        }
    }

    public void aj_() {
        ॱ(this.ˏ, this.ˋ, this.ˎ, this.ᐝ);
    }

    public void ak_() {
    }
}
